# import whisper

# model = whisper.load_model("turbo")
# result = model.transcribe("test.mp3")
# print(result["text"])

import sys
print(sys.executable)

import whisper

# 加载 Whisper 模型
model = whisper.load_model("turbo")

# 识别音频文件
def transcribe_with_hotword(audio_file, hotwords):
    result = model.transcribe(audio_file)
    transcription = result["text"]
    print("Transcription:", transcription)

    # 检查是否有热词
    for hotword in hotwords:
        if hotword.lower() in transcription.lower():
            print(f"Hotword '{hotword}' detected!")
    
    return transcription

# 示例音频和热词列表
audio_file = "/home/oem/know_prj/record/record2_content.wav"
hotwords = ["吴兴区", "小知", "start"]

# 调用函数进行语音识别和热词检测
transcription = transcribe_with_hotword(audio_file, hotwords)

# import pyaudio
# import whisper
# import numpy as np
# import time

# # 设置音频录制的参数
# RATE = 16000  # 采样率
# CHUNK = 1024  # 每次读取的数据块大小
# FORMAT = pyaudio.paFloat32
# CHANNELS = 1  # 单声道

# # 初始化 Whisper 模型
# model = whisper.load_model("turbo")

# # 初始化 PyAudio
# p = pyaudio.PyAudio()

# # 打开麦克风流
# stream = p.open(format=FORMAT,
#                 channels=CHANNELS,
#                 rate=RATE,
#                 input=True,
#                 frames_per_buffer=CHUNK)

# print("开始实时语音识别...")

# try:
#     while True:
#         # 读取原始音频数据
#         audio_data = stream.read(CHUNK)
        
#         # 转为np数组
#         audio_np = np.frombuffer(audio_data, dtype=np.float32)

#         # 使用 Whisper 进行转录
#         result = model.transcribe(audio_np)
        
#         # 打印识别结果
#         print("识别结果:", result["text"])

#         # 为了避免打印过快，可以适当延迟一下
#         time.sleep(0.1)

# except KeyboardInterrupt:
#     print("实时识别结束")

# finally:
#     # 关闭麦克风流
#     stream.stop_stream()
#     stream.close()
#     p.terminate()

